//
//  JoinINMainViewController.m
//  消费100
//
//  Created by eliot on 16/3/31.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "JoinINMainViewController.h"
#import "JoinInPurchasesTableViewCell.h"
#import "WinningTableViewCell.h"
#import "StepForPurchasesTableViewCell.h"
#import "CommtiTableViewController.h"
#import "AllPurchasesHistoryTableViewController.h"
#import "PeriodsViewController.h"
#import "UIImageView+WebCache.h"
@interface JoinINMainViewController ()<UITableViewDataSource, UITableViewDelegate>


@property (weak, nonatomic) IBOutlet UIView *btnBGV;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *submitBtnTop;


@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet UIView *bottomView;

@property (weak, nonatomic) IBOutlet UIImageView *bottomViewIcon;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewTitleLbTop;


@property (weak, nonatomic) IBOutlet UILabel *bottomViewTitleLb;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewTitleLbH;

@property (weak, nonatomic) IBOutlet UILabel *bottomViewPriceLb;

@property (weak, nonatomic) IBOutlet UIButton *releaseBtn;

@property (weak, nonatomic) IBOutlet UILabel *bottomViewCiShuCountLb;

@property (weak, nonatomic) IBOutlet UIButton *addBtn;


@property (weak, nonatomic) IBOutlet UILabel *goldCountLb;

@property (weak, nonatomic) IBOutlet UIButton *submitJoinBtn;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewIconH;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *submitBtnH;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewIconW;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewH;


/** 步骤cell的高度*/
@property (nonatomic) float cellHeightAtFive;
/** 是否隐藏*/
@property (nonatomic, assign) BOOL isHiddenStepCell;
/** 流程图片*/
@property (nonatomic, strong) UIImageView *stepIV;
/** 遮盖视图*/
@property (nonatomic, strong) UIView *blackView;


/** 数据源*/
@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation JoinINMainViewController


static int page = 1;


- (void)dealloc {

    page = 1;
}

- (NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

+(JoinINMainViewController*)CreatJoinINMainViewController{
    
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    JoinINMainViewController *JoinINMainViewController=[story instantiateViewControllerWithIdentifier:@"JoinINMainViewController"];
    return JoinINMainViewController;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [UIView animateWithDuration:0.25 animations:^{
        
        self.bottomViewH.constant = 0;
        
        self.blackView.hidden = YES;
    }];
    
}

-(UIView *)blackView {
    if (!_blackView) {
        //灰色背景
        _blackView = [[UIView alloc] init];
        [self.view addSubview:_blackView];
        [_blackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.mas_equalTo(0);
            
            if (Width >320) {
                make.bottom.mas_equalTo(-195 / 320.0 *Width - 20);
            }else {
                make.bottom.mas_equalTo(-195 / 320.0 *Width - 40);
            }
            make.bottom.mas_equalTo(-195 / 320.0 *Width - 20);
        }];
        _blackView.backgroundColor = [UIColor colorWithRed:160/255.0 green:160/255.0 blue:160/255.0 alpha:0.25];
    }
    return _blackView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.isHiddenStepCell = YES;
    
    self.bottomViewH.constant = 0;
    self.submitBtnH.constant = 40;
    
    self.bottomViewIconW.constant = 67 / 320.0 *Width;
    self.bottomViewIconH.constant = 77 / 320.0 *Width;
    if (Width <= 320) {
        self.bottomViewTitleLbTop.constant = 10 / 320.0* Width;
    }else {
        self.bottomViewTitleLbTop.constant = 10 / 320.0* Width + 10;
    }
   
    
    self.submitJoinBtn.layer.cornerRadius = 8;
    self.submitJoinBtn.layer.masksToBounds = YES;
    
    self.bottomViewCiShuCountLb.layer.borderWidth = 1;
    self.bottomViewCiShuCountLb.layer.borderColor = [[UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1] CGColor];
    
    self.btnBGV.layer.borderWidth = 1;
    self.btnBGV.layer.borderColor = [[UIColor colorWithRed:227/255.0 green:227/255.0 blue:227/255.0 alpha:1] CGColor];
    self.btnBGV.layer.cornerRadius = 8;
    self.btnBGV.layer.masksToBounds = YES;
    
   self.bottomViewTitleLb.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
    UIFont *font = [UIFont fontWithName:@"Arial" size:14];
    self.bottomViewTitleLb.numberOfLines = 0;
    //设置字体
    self.bottomViewTitleLb.font = font;
    CGSize maxSize = CGSizeMake(Width - 89, CGFLOAT_MAX);
    NSStringDrawingOptions opts = NSStringDrawingUsesLineFragmentOrigin |
    NSStringDrawingUsesFontLeading;
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByCharWrapping];
    
    NSDictionary *attributes = @{ NSFontAttributeName : font, NSParagraphStyleAttributeName : style };
    CGRect rect1 = [self.bottomViewTitleLb.text boundingRectWithSize:maxSize options:opts attributes:attributes context:nil];
    self.bottomViewTitleLbH.constant = rect1.size.height;
    
    
    self.submitBtnTop.constant = 10;
    self.submitJoinBtn.backgroundColor = [UIColor colorWithRed:255/255.0 green:88/255.0 blue:88/255.0 alpha:1];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"JoinInPurchasesTableViewCell" bundle:nil] forCellReuseIdentifier:@"JoinInPurchasesTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WinningTableViewCell" bundle:nil] forCellReuseIdentifier:@"WinningTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"StepForPurchasesTableViewCell" bundle:nil] forCellReuseIdentifier:@"StepForPurchasesTableViewCell"];
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.title = @"Apple IPhone 6s(A1700)16G金色 移动联通电信4G手机";
    /** 设置导航啦样式*/
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;

    
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer.timeoutInterval = 5;
    NSDictionary *dic = @{@"crowdfundingId":self.crowdfundingId,@"page":@"1"};
   
    NSString *baseUrl = [NSString stringWithFormat:@"%@getCrowdfundingById.jhtml", MyBaseURL];
    [manager POST:baseUrl parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            self.dataArr = dic[@"crowdfundingJson"];

            [self.tableView reloadData];
        });
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUD];
            [MBProgressHUD showError:@"链接超时,请检查网络"];
        });
    }];
    
    
    
    
    
}





#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.isHiddenStepCell) {
        return 7;
    }else {
        return 8;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.isHiddenStepCell == 1) {
        switch (indexPath.row) {
            case 0:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                }
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.textLabel.text = @"第一期";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                iv.frame = CGRectMake(0, 0, 12, 12);
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
                cell.detailTextLabel.text = @"以往期数";
                return cell;
            }
                break;
            case 1:
            {
                JoinInPurchasesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JoinInPurchasesTableViewCell" forIndexPath:indexPath];
                cell.iconIVH.constant = 158 / 320.0 *Width;
                // 设置Label的字体 HelveticaNeue  Courier
                UIFont *fnt = [UIFont systemFontOfSize:15];
                cell.titleLb.font = fnt;
                cell.titleLb.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
              
                // 根据字体得到NSString的尺寸
                CGSize size = [cell.titleLb.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
                // 名字的H
                CGFloat nameH = size.height;
                // 名字的W
                //            CGFloat nameW = size.width;
                cell.titleLbH.constant = nameH + 10;
                cell.titleLbTop.constant = 0;
                cell.titleLb.numberOfLines = 0;
                cell.firstView.backgroundColor = [UIColor colorWithRed:252/255.0 green:220/255.0 blue:95/255.0 alpha:1];
                cell.secondView.backgroundColor = [UIColor colorWithRed:254/255.0 green:220/255.0 blue:95/255.0 alpha:1];
                cell.thridView.backgroundColor = [UIColor colorWithRed:254/255.0 green:220/255.0 blue:95/255.0 alpha:1];
                cell.firstViewH.constant = cell.firstViewW.constant =cell.secondViewH.constant =cell.secondViewW.constant =cell.thridViewH.constant =cell.thridViewW.constant =60 / 320.0 *Width;
                cell.bigViewH.constant = cell.bigVIewW.constant = 60 / 320.0 * Width + 15;
                cell.firstView.layer.cornerRadius = 30 / 320.0 *Width;
                cell.firstView.layer.masksToBounds = YES;
                cell.secondView.layer.cornerRadius = 30 / 320.0 *Width;
                cell.secondView.layer.masksToBounds = YES;
                cell.thridView.layer.cornerRadius = 30 / 320.0 *Width;
                cell.thridView.layer.masksToBounds = YES;
                cell.bigView.layer.cornerRadius = 37 / 320.0 *Width;
                cell.bigView.layer.masksToBounds = YES;
                cell.bigView.layer.borderWidth = 1;
                cell.bigView.layer.borderColor = [[UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1] CGColor];
                
                cell.firstViewLbTop.constant = cell.firstViewH.constant / 2 - 20;
                
                cell.secondViewLbTop.constant = cell.firstViewH.constant / 2 - 20;
                
                cell.thridViewLbTop.constant = cell.firstViewH.constant / 2 - 20;
                
                NSDictionary *tempDic = self.dataArr.firstObject;
                [cell.iconIV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.188:8080%@", tempDic[@"crowdfundindIMG"]]]];
                
                cell.titleLb.text = tempDic[@"name"];
                cell.descLb.text = tempDic[@"content"];
                cell.priceLb.text = [NSString stringWithFormat:@"￥%@", tempDic[@"price"]];
                cell.totalCount.text = [NSString stringWithFormat:@"￥%@", tempDic[@"inNum"]];
                cell.joinedLb.text = [NSString stringWithFormat:@"￥%@", tempDic[@"countNum"]];
                
                cell.toBeJoinedLb.text = [NSString stringWithFormat:@"%d", [tempDic[@"inNum"] intValue] - [tempDic[@"countNum"] intValue]];
                
                return cell;
            }
                break;
            case 2:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                }
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.textLabel.text = @"所有众购记录";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                iv.frame = CGRectMake(0, 0, 12, 12);
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
                return cell;
            }
                break;
            case 3:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                }
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.textLabel.text = @"图文详情";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                iv.frame = CGRectMake(0, 0, 12, 12);
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
                return cell;
            }
                break;
            case 4:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.textLabel.text = @"众筹流程";
                self.stepIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                self.stepIV.frame = CGRectMake(0, 0, 12, 12);
                self.stepIV.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = self.stepIV;
                return cell;
            }
                break;
            case 5:
            {
                WinningTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WinningTableViewCell" forIndexPath:indexPath];
                cell.iconIVH.constant = 76 / 320.0 *Width;
                cell.iconIVW.constant = 75 / 320.0 *Width;
                // 设置Label的字体 HelveticaNeue  Courier
                UIFont *fnt = [UIFont systemFontOfSize:14];
                cell.nameLb.font = fnt;
                // 根据字体得到NSString的尺寸
                CGSize size = [cell.nameLb.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
                // 名字的H
                CGFloat namew = size.width;
                cell.nameLbW.constant = namew;
                cell.iconIV.layer.cornerRadius = 40 / 320.0 *Width;
                cell.iconIV.layer.masksToBounds = YES;
                return cell;
            }
                break;
            default:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lastCell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"lastCell"];
                }
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                [cell addSubview:btn];
                btn.backgroundColor = [UIColor colorWithRed:255/255.0 green:88/255.0 blue:88/255.0 alpha:1];
                [btn setTitle:@"立即参与众购" forState:UIControlStateNormal];
                [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(20);
                    make.right.mas_equalTo(-20);
                    make.top.mas_equalTo(20);
                    make.height.mas_equalTo(40);
                }];
                [btn addTarget:self action:@selector(joinInPurchases) forControlEvents:UIControlEventTouchUpInside];
                btn.layer.cornerRadius = 6;
                btn.layer.masksToBounds = YES;
                cell.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
                return cell;
            }
                break;
        }
        
    }else {
        switch (indexPath.row) {
            case 0:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                }
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.textLabel.text = @"第一期";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                iv.frame = CGRectMake(0, 0, 12, 12);
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
                cell.detailTextLabel.text = @"以往期数";
                return cell;
            }
                break;
            case 1:
            {
                JoinInPurchasesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JoinInPurchasesTableViewCell" forIndexPath:indexPath];
                cell.iconIVH.constant = 158 / 320.0 *Width;
                // 设置Label的字体 HelveticaNeue  Courier
                UIFont *fnt = [UIFont systemFontOfSize:15];
                cell.titleLb.font = fnt;
                cell.titleLb.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                // 根据字体得到NSString的尺寸
                CGSize size = [cell.titleLb.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
                // 名字的H
                CGFloat nameH = size.height;
                // 名字的W
                //            CGFloat nameW = size.width;
                cell.titleLbH.constant = nameH + 10;
                cell.titleLbTop.constant = 0;
                cell.titleLb.numberOfLines = 0;
                cell.firstViewH.constant = cell.firstViewW.constant =cell.secondViewH.constant =cell.secondViewW.constant =cell.thridViewH.constant =cell.thridViewW.constant =60 / 320.0 *Width;
                cell.bigViewH.constant = cell.bigVIewW.constant = 60 / 320.0 * Width + 15;
                cell.firstView.layer.cornerRadius = 30 / 320.0 *Width;
                cell.firstView.layer.masksToBounds = YES;
                cell.secondView.layer.cornerRadius = 30 / 320.0 *Width;
                cell.secondView.layer.masksToBounds = YES;
                cell.thridView.layer.cornerRadius = 30 / 320.0 *Width;
                cell.thridView.layer.masksToBounds = YES;
                cell.bigView.layer.cornerRadius = 37 / 320.0 *Width;
                cell.bigView.layer.masksToBounds = YES;
                cell.bigView.layer.borderWidth = 1;
                cell.bigView.layer.borderColor = [[UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1] CGColor];
                return cell;
            }
                break;
            case 2:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                }
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.textLabel.text = @"所有众购记录";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                iv.frame = CGRectMake(0, 0, 12, 12);
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
                return cell;
            }
                break;
            case 3:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                }
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.textLabel.text = @"图文详情";
                UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows"]];
                iv.frame = CGRectMake(0, 0, 12, 12);
                iv.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = iv;
                return cell;
            }
                break;
            case 4:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.textLabel.textColor = [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1];
                cell.textLabel.text = @"众筹流程";
                self.stepIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrowsD"]];
                self.stepIV.frame = CGRectMake(0, 0, 12, 12);
                self.stepIV.contentMode = UIViewContentModeScaleAspectFit;
                cell.accessoryView = self.stepIV;
                return cell;
            }
                break;
            case 5:
            {
                StepForPurchasesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StepForPurchasesTableViewCell" forIndexPath:indexPath];
                cell.lb2H.constant = 79.0 / Width *320;
                cell.lb4H.constant = 79.0 / Width *320;
                cell.lb6H.constant = 79.0 / Width *320;
                cell.lb2.text = @"你在哪里";
                UIFont *font = [UIFont fontWithName:@"Arial" size:12];
                //设置字体
                cell.lb2.font = font;
                cell.lb4.font = font;
                cell.lb6.font = font;
                //            size = [cell.lb2.text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];//ios7以前的
                CGSize maxSize = CGSizeMake(Width - 16, CGFLOAT_MAX);
                NSStringDrawingOptions opts = NSStringDrawingUsesLineFragmentOrigin |
                NSStringDrawingUsesFontLeading;
                
                NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
                [style setLineBreakMode:NSLineBreakByCharWrapping];
                
                NSDictionary *attributes = @{ NSFontAttributeName : font, NSParagraphStyleAttributeName : style };
                
                CGRect rect1 = [cell.lb2.text boundingRectWithSize:maxSize
                                                           options:opts
                                                        attributes:attributes
                                                           context:nil];
                CGRect rect2 = [cell.lb4.text boundingRectWithSize:maxSize
                                                           options:opts
                                                        attributes:attributes
                                                           context:nil];
                CGRect rect3 = [cell.lb6.text boundingRectWithSize:maxSize
                                                           options:opts
                                                        attributes:attributes
                                                           context:nil];
                cell.lb2H.constant = rect1.size.height;
                cell.lb4H.constant = rect2.size.height;
                cell.lb6H.constant = rect3.size.height;
                
                self.cellHeightAtFive =  cell.lb2H.constant + cell.lb4H.constant + cell.lb6H.constant + 24 + 15 + 60;
                return cell;
            }
                break;
            case 6:
            {
                WinningTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WinningTableViewCell" forIndexPath:indexPath];
                cell.iconIVH.constant = 76 / 320.0 *Width;
                cell.iconIVW.constant = 75 / 320.0 *Width;
                // 设置Label的字体 HelveticaNeue  Courier
                UIFont *fnt = [UIFont systemFontOfSize:14];
                cell.nameLb.font = fnt;
                // 根据字体得到NSString的尺寸
                CGSize size = [cell.nameLb.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
                // 名字的H
                CGFloat namew = size.width;
                cell.nameLbW.constant = namew;
                cell.iconIV.layer.cornerRadius = 40 / 320.0 *Width;
                cell.iconIV.layer.masksToBounds = YES;
                return cell;
            }
                break;
            default:
            {
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lastCell"];
                if (!cell) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"lastCell"];
                }
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                [cell addSubview:btn];
                btn.backgroundColor = [UIColor colorWithRed:255/255.0 green:88/255.0 blue:88/255.0 alpha:1];
                [btn setTitle:@"立即参与众购" forState:UIControlStateNormal];
                [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(20);
                    make.right.mas_equalTo(-20);
                    make.top.mas_equalTo(20);
                    make.height.mas_equalTo(40);
                }];
                [btn addTarget:self action:@selector(joinInPurchases) forControlEvents:UIControlEventTouchUpInside];
                btn.layer.cornerRadius = 6;
                btn.layer.masksToBounds = YES;
                cell.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
                return cell;
            }
                break;
        }
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.isHiddenStepCell) {
        switch (indexPath.row) {
            case 0:
                return 44;
                break;
            case 1:
                if (Width <= 320.0f) {
                    return 335 / 320.0 * Width;
                }else {
                    return 335 / 320.0 * Width - 20;
                    
                }
                break;
            case 2:
                return 44;
                break;
            case 3:
                return 44;
                break;
            case 4:
                return 44;
                break;
            case 5:
                return 120 / 320.0 * Width;
                break;
            default:
                return 100 / 320.0 * Width;
                break;
        }
        
    }else {
        switch (indexPath.row) {
            case 0:
                return 44;
                break;
            case 1:
                if (Width <= 320.0f) {
                    return 335 / 320.0 * Width;
                }else {
                    return 335 / 320.0 * Width - 20;
                }
                break;
            case 2:
                return 44;
                break;
            case 3:
                return 44;
                break;
            case 4:
                return 44;
                break;
            case 5:
                return  self.cellHeightAtFive;
                break;
            case 6:
                return 120 / 320.0 * Width;
                break;
            default:
                return 100 / 320.0 * Width;
                break;
        }
        
    }
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        PeriodsViewController *vc = [PeriodsViewController CreatPeriodsViewController];
        [self creatNav:vc];
        
    }
    
    
    if (indexPath.row == 2) {
        AllPurchasesHistoryTableViewController *vc = [AllPurchasesHistoryTableViewController CreatAllPurchasesHistoryTableViewController];
         NSDictionary *tempDic = self.dataArr.firstObject;

        vc.productId = tempDic[@"id"];
        [self creatNav:vc];
  
    }
    
    if (indexPath.row == 4) {
        self.isHiddenStepCell = !self.isHiddenStepCell;
        [UIView animateWithDuration:0.25 animations:^{
            [self.tableView reloadData];
            
        }];
    }
    
    
}


/** 点击立即参与众筹*/
- (void)joinInPurchases {
    
    [UIView animateWithDuration:0.25 animations:^{
        if (Width >320) {
            self.bottomViewH.constant = 195 / 320.0 *Width + 20;
        }else {
            self.bottomViewH.constant = 195 / 320.0 *Width + 40;
        }
        
        
        self.blackView.hidden = NO;
    }];

}


/** 点击增加次数*/

- (IBAction)clickAddBtn:(id)sender {
    
    self.bottomViewCiShuCountLb.text = [NSString stringWithFormat:@"%d", [self.bottomViewCiShuCountLb.text intValue] + 1];
    
}

/** 点击减少次数*/

- (IBAction)clickReleaseBtn:(id)sender {
    
    if ([self.bottomViewCiShuCountLb.text intValue] >= 1) {
        self.bottomViewCiShuCountLb.text = [NSString stringWithFormat:@"%d", [self.bottomViewCiShuCountLb.text intValue] - 1];
    }
    
    
}




/** 点击确定参与*/
- (IBAction)clickyesJoinBtn:(id)sender {
    
    
    CommtiTableViewController *vc = [CommtiTableViewController CreatTransactionDetailsTableViewController];
    [self creatNav:vc];
    
}

//创建模态导航控制器
-(void)creatNav:(UIViewController *)view{
    
    UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
    nav.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    view.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    [self presentViewController:nav animated:YES completion:nil];
}

- (void)dismiss {
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}






/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
